package com.qf.attendance.controller;


import com.baomidou.mybatisplus.core.metadata.IPage;
import com.qf.attendance.qo.MeritsQO;
import com.qf.attendance.service.MeritsService;
import com.qf.attendance.vo.MeritsApproveVO;
import com.qf.common.base.result.RespResult;
import io.swagger.annotations.*;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;

@RestController
@RequestMapping("/merits")
public class MeritsController {
    @Resource
    private MeritsService meritsService;

    @ApiOperation("查询绩效")
    @GetMapping("/list")
    @ApiImplicitParams({@ApiImplicitParam(name = "page", value = "页码"), @ApiImplicitParam(name = "size", value = "条数")})
    @ApiResponses({@ApiResponse(code = 200, message = "成功")})
    public RespResult<IPage<MeritsApproveVO>> list(@RequestParam(defaultValue = "1") int page, @RequestParam(defaultValue = "10") int size) {
        return RespResult.success(meritsService.list(page, size));
    }

    @ApiOperation("特定条件查询绩效信息")
    @PostMapping("/selectList")
    @ApiImplicitParams({@ApiImplicitParam(name = "page", value = "页码"), @ApiImplicitParam(name = "size", value = "条数"), @ApiImplicitParam(name = "meritsQO", value = "查询条件对象")})
    @ApiResponses({@ApiResponse(code = 200, message = "成功")})
    public RespResult<IPage<MeritsApproveVO>> selectList(@RequestParam(defaultValue = "1") int page, @RequestParam(defaultValue = "10") int size, MeritsQO meritsQO) {
        return RespResult.success(meritsService.selectList(page, size, meritsQO));
    }


    @ApiOperation("添加绩效记录")
    @PostMapping("/insert")
    @ApiImplicitParams({@ApiImplicitParam(name = "meritsQO", value = "添加对象")})
    @ApiResponses({@ApiResponse(code = 200, message = "成功")})
    public RespResult insert(@RequestBody MeritsQO meritsQO) {
        return meritsService.insert(meritsQO);
    }

    @ApiOperation("修改绩效记录")
    @PostMapping("/update")
    @ApiImplicitParam(name = "meritsQO", value = "修改信息对象")
    @ApiResponses({@ApiResponse(code = 200, message = "成功")})
    public RespResult update(@RequestBody MeritsQO meritsQO) {
        return meritsService.update(meritsQO);
    }

    @ApiOperation("删除绩效记录")
    @GetMapping("/delete")
    @ApiImplicitParam(name = "meritsId", value = "绩效ID")
    @ApiResponses({@ApiResponse(code = 200, message = "成功")})
    public RespResult delete(@RequestParam int meritsId) {
        return meritsService.delete(meritsId);
    }
}
